import java.util.Stack;

class Solution {
    public static void main(String[] args) {
        ListNode listNode1 = new ListNode(1);
        ListNode listNode2 = new ListNode(2);;
        ListNode listNode3 = new ListNode(3);;
        ListNode listNode4 = new ListNode(3);;
        ListNode listNode5 = new ListNode(4);;
        ListNode listNode6 = new ListNode(4);;
        ListNode listNode7 = new ListNode(5);;
        listNode1.next = listNode2;
        listNode2.next = listNode3;
        listNode3.next = listNode4 ;
        listNode4.next = listNode5 ;
        listNode5.next = listNode6 ;
        listNode6.next = listNode7;
       deleteDuplicates(listNode1);

    }
    public static int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>() ;
        for(int i =0  ;i < tokens.length ; i ++){
            String str = tokens[i] ;
            if(str.equals("+") || str.equals("-")  || str.equals("*") || str.equals("/")){
                if(str.equals("+")){
                    int b = stack.pop() ;
                    int a = stack.pop() ;
                    int tmp = a + b ;
                    stack.push(tmp);
                }else if(str.equals("-")){
                    int b = stack.pop() ;
                    int a = stack.pop() ;
                    int tmp = a - b ;
                    stack.push(tmp);
                }else if(str.equals("*")){
                    int b = stack.pop() ;
                    int a = stack.pop() ;
                    int tmp = a * b ;
                    stack.push(tmp);
                }else {
                    int b = stack.pop() ;
                    int a = stack.pop() ;
                    int tmp = a / b ;
                    stack.push(tmp);
                }
            }else{
                int tmp = Integer.parseInt(str);
                stack.push(tmp);
            }
        }
        return stack.pop() ;
    }
    class Solution {
        public ListNode deleteDuplicates(ListNode head) {
            ListNode newHead = new ListNode() ;
            ListNode newLast = newHead ;
            ListNode cur = head ;
            while(cur != null ){
                ListNode curNext = cur.next ;
                while(curNext !=null && cur.val == curNext.val){
                    curNext = curNext.next ;
                }
                if( cur.next != curNext){
                    cur = curNext;
                }else{
                    newLast.next = cur ;
                    newLast = cur ;
                    cur = cur.next ;
                }

            }

            if(newLast!=null){
                newLast.next = null ;
            }
            return newHead.next ;

        }
    }

 class  ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }